package com.gy.api.pc.enterprise.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import com.github.pagehelper.PageInfo;
import com.gy.api.base.*;
import com.gy.api.pc.enterprise.domain.vo.EnterpriseCompleteVO;
import com.gy.api.pc.enterprise.domain.vo.EnterpriseDescVO;
import com.gy.api.pc.enterprise.domain.vo.EnterpriseSearchVO;
import com.gy.api.pc.enterprise.domain.vo.EnterpriseVO;
import com.gy.api.pc.enterprise.service.IEnterpriseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/workFlow/companyApply")
@Api( tags = ApiIndex.EnterpriseController)
@Slf4j
public class EnterpriseController {

    @Autowired
    private IEnterpriseService service;

    @ApiOperation(value = "查询单位相关申请信息记录列表-全部")
    @GetMapping(value = "/list")
    @SaCheckLogin
    public R<RestPage<List<EnterpriseVO>>> list(
            @ApiParam(value = "查询参数") @ModelAttribute EnterpriseSearchVO searchVO) {
        searchVO.setApprovalStatus(null);
        List<EnterpriseVO> list = service.getList(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }


    @ApiOperation(value = "查询单位相关申请信息【初审或审查决定】记录列表")
    @GetMapping(value = "/initialOrDecisionReviewList")
    @SaCheckLogin
    public R<RestPage<List<EnterpriseVO>>> list_one(
            @ApiParam(value = "查询参数") @ModelAttribute EnterpriseSearchVO searchVO) {
        if(searchVO.getApprovalStatus()==null){
            searchVO.setApprovalStatus(1);
        }
        searchVO.setUserId(StpUtil.getLoginIdAsString());
        List<EnterpriseVO> list = service.getListOne(searchVO);
        RestPage restPage = new RestPage( new PageInfo(list),list);
        return new R(restPage);
    }

    @ApiOperation(value = "查询-企业办事认证详情")
    @GetMapping(value = "/{applyId}")
    @SaCheckLogin
    public R<EnterpriseDescVO> desc(@ApiParam("业务ID") @PathVariable("applyId") String applyId) {
        EnterpriseDescVO desc = service.getDesc(applyId);
        return new R(desc);
    }

    @ApiOperation("完成审批")
    @PostMapping("/complete")
    @SaCheckLogin
    public R complete(@RequestBody EnterpriseCompleteVO taskCompleteDto){
        service.completeTask(taskCompleteDto);
        return new R();
    }

}
